/*
 * DBConnector.java
 *
 * Created on August 27, 2002, 10:10 AM
 */

package com.ebrothers.isns.dao;

/**
 *
 * @author  gcai
 */

// Necessary classes to get Pooled Database Connection
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * This class defines getConnection and releaseConnection methods. In
 * getConnection method, connection caching feature of JDBC 2.0 is implemented
 * to get the database connection.
 */
public class DBConnector {
	private static DBConnector connector_ = null;

	// Create a sinlgeton object
	public static DBConnector getInstance() throws Exception {
		return connector_;
	}

	// Create a sinlgeton object
	public static DBConnector getInstance(String url, String user,
			String password) throws Exception {
		if (connector_ == null) {
			connector_ = new DBConnector(url, user, password);
		}

		return connector_;
	}

	private String mUrl;
	private String mUser;
	private String mPassword;

	/**
	 * Default Constructor. Takes no arguments
	 */
	private DBConnector() throws SQLException {
	}

	private DBConnector(String url, String user, String password)
			throws Exception {
		mUrl = url;
		mUser = user;
		mPassword = password;
		Class.forName("com.mysql.jdbc.Driver");
	}

	public Connection getConnection() throws SQLException {
		return DriverManager.getConnection(mUrl, mUser, mPassword);
	}

}
